using System;

namespace BehaviorSystem
{
    public class BehaviorInfo
    {
        private int[] _priorityData;
        private int _CDDuration;
        private int _remainCD;
        private bool _isActive;
        private BehaviorInfo()
        {
            _priorityData = new int[4];
            _remainCD = 0;
            IsActive = false;
        }
        public BehaviorInfo(int coldDownDuration, params int[] priorityData) : this()
        {
            _CDDuration = coldDownDuration;
            for (int i = 0; i < 4; i++) _priorityData[i] = Math.Max(priorityData[i], 0);
        }
        public BehaviorInfo(string infoString) : this()
        {
            string[] info = infoString.Split("/");
            _CDDuration = int.Parse(info[0]);
            for (int i = 0; i < 4; i++) _priorityData[i] = Math.Max(int.Parse(info[i + 1]), 0);
        }

        /// <summary>
        /// 0: movement; 1: single hit; 2: command move; 3: super move; 4:climax move; and so on.
        /// </summary>
        public int Priority { get => _priorityData[0]; }
        /// <summary>
        /// The bigger, the higher the priority in the manager filter is.
        /// </summary>
        public int InnerPriority { get => _priorityData[1]; }
        public int BehaviorKey { get => _priorityData[2]; }
        /// <summary>
        /// The move, at the same priority and cancelLevel, whose key is equal to this is able to perform.
        /// </summary>
        public int OptionalBehaviorKey { get => _priorityData[3]; }
        public bool IsActive { get => _isActive; private set => _isActive = value; }
        public bool IsReady { get => _remainCD == 0; }

        public void Activate() { IsActive = true; }
        public void Deactivate() { IsActive = false; }
        public void ResetCD() { _remainCD = _CDDuration; } 
        public void RefreshCD() { _remainCD = 0; }
        public void CoolDown() { _remainCD = Math.Max(0, --_remainCD); }
    }
}
